﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ConsoleApplication1;
using ClassLibrary1.entity;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        List<TextBox> tblist = new List<TextBox>();
        List<string> list = new List<string>();
        Form1 root;
        public Form3(Form1 root,Type t,string id)
        {
            InitializeComponent();

            this.root = root;

            Label l;
            TextBox tb;
            int ly = 71, lx = 35, tby = 68, tbx = 86;
            
            foreach (var f in t.GetFields().Reverse())
            {
                l = new Label();
                l.Location = new Point(lx, ly);
                ly += 25;
                l.Size = new Size(36, 13);
                l.Text = f.Name;

                tb = new TextBox();
                tb.Location = new Point(tbx, tby);
                tby += 25;
                tb.Size = new Size(86, 20);
                tblist.Add(tb);

                this.Controls.Add(l);
                this.Controls.Add(tb);
            }

            tblist.ElementAt(0).Text = id;
            tblist.ElementAt(0).ReadOnly = true;

            list.Add("update");
            list.Add(t.Name.ToLower());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (TextBox i in tblist)
            {
                list.Add(i.Text.Trim());
            }
            try
            {
                CProgram.RunCommand(list.ToArray());
            }
            catch (Exception) { }
            this.Dispose();
            this.Close();
            root.cbox_entity_SelectedIndexChanged(null, null);
        } 
    }
}
